#include <REGX52.H>
#include "LCD1602.h"
#include "timer0.h"

unsigned char second, minute, hour;

void main()
{
	LCD_Init();
	timer0_init();
	
	LCD_ShowString(1, 1, "Clock:");
	LCD_ShowString(2, 1, "  :  :");
	
	while(1)
	{
		LCD_ShowNum(2, 1, hour, 2);
		LCD_ShowNum(2, 4, minute, 2);
		LCD_ShowNum(2, 7, second, 2);
	}
}


void Time0_Rountine() interrupt 1
{
	static unsigned int t0Count;
	TL0 = 0x18;		//设置定时初值
	TH0 = 0xFC;		//设置定时初值
	
	t0Count++; //t0Count计次，对中断频率进行分频
	// 分频1000次，大于1s，计数器重置为0
	if(t0Count >= 1000)
	{
		t0Count = 0;
		second++;
		if(second >= 60)
		{
			second = 0;
			minute++;
			if(minute >= 60)
			{
				minute = 0;
				hour++;
				if(hour >= 24)
				{
					hour = 0;
				}
			}
		}
	}
}